﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ManagePeople.ascx.cs" Inherits="ManagePeople" %>
<%@ Register assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" namespace="System.Web.UI.WebControls" tagprefix="asp" %>

<script type="text/javascript" language="javascript">
    function confirm() {
        alert("This is my alert message");
    }
</script>

<h3>Manage People</h3>

<div  class="featurebox_center">
<%--add new person button--%>
<%--<asp:Button ID="btnAddNewPerson" runat="server" Text="Add New Person" 
    onclick="btnAddNewPerson_Click" />
<br />
<br />--%>

<%--search for a person--%>
<h4><asp:Label ID="lblSearch" runat="server" Text="Search by Id, Last Name, Phone Number, or Email: "></asp:Label></h4>
<br />
<asp:TextBox ID="txtFindPerson" runat="server"></asp:TextBox>
&nbsp;&nbsp;
<asp:Button ID="btnFindPerson" runat="server" Text="Find Person" onclick="btnFindPerson_Click" />
<asp:Button ID="test2" runat="server" Text="javascript test 2"  />
<button ID="test1" runat="server" title="javascript test 1"  onclick="confirm();" />
<br />
<br />

<%--grid displays results of searching for a person--%>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataKeyNames="PersonID" DataSourceID="SqlDataSource2" AllowPaging="True" 
    AllowSorting="True"  
    onselectedindexchanged="GridView1_SelectedIndexChanged">
    <Columns>
        <asp:BoundField DataField="PersonId" HeaderText="Id" SortExpression="Id" />
        <asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="First Name" />
        <asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="Last Name" />
        <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
        <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
        <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" 
            ControlStyle-Width="30px" > <ControlStyle Width="30px"></ControlStyle></asp:BoundField>
        <asp:BoundField DataField="Zip" HeaderText="Zip" SortExpression="Zip" />
        <asp:BoundField DataField="PhoneNumber" HeaderText="Phone Number" ControlStyle-Width="96px"
            SortExpression="PhoneNumber" > <ControlStyle Width="95px"></ControlStyle> </asp:BoundField>
        <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
        <asp:BoundField DataField="Level" HeaderText="Employee Level" NullDisplayText="Not An Employee" />
        <asp:CommandField ShowSelectButton="True" SelectText="Select" ButtonType="Button" 
            EditText="Select" />
    </Columns>
    <HeaderStyle Font-Bold="True" ForeColor="#2153AA" />
</asp:GridView>

<%--sql data source for data grid and detail view--%>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="<%$ ConnectionStrings:BPI_LibraryConnectionString %>" 
    SelectCommand="usp_PERSON_FindPersonEmployee" SelectCommandType="StoredProcedure" 
    UpdateCommand="usp_PERSON_UpdatePersonEmployee" UpdateCommandType="StoredProcedure" 
    InsertCommand="usp_PERSON_InsertPerson" InsertCommandType="StoredProcedure" >
    <SelectParameters>
        <asp:ControlParameter ControlID="txtFindPerson" Name="value"
            PropertyName="Text" Type="String" />
    </SelectParameters>
    
</asp:SqlDataSource>

<%--sql data source for state drop down box--%>
<asp:SqlDataSource ID="sqlDataSource_states" runat="server" 
    ConnectionString="<%$ ConnectionStrings:BPI_LibraryConnectionString %>" 
    SelectCommand="sp_GetStates" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>

<%--sql datasource for details view--%>
<asp:SqlDataSource 
    ID="SqlDataSource3" runat="server"
    ConnectionString="<%$ ConnectionStrings:BPI_LibraryConnectionString %>" 
    SelectCommand="SELECT * FROM [PERSON] LEFT JOIN [EMPLOYEE] ON [PERSON].[PersonID] = [EMPLOYEE].[PersonID] WHERE [PERSON].[PersonID] = @PersonID and [EMPLOYEE].[PersonID] = @PersonID"
    UpdateCommand="usp_PERSON_UpdatePersonEmployee" UpdateCommandType="StoredProcedure"
    InsertCommand="usp_PERSON_InsertPersonEmployee" InsertCommandType="StoredProcedure">
    <SelectParameters>
        <asp:ControlParameter ControlID="GridView1" Name="PersonID"  
            PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>
<br />
    <asp:Button ID="btnAddNew" runat="server" Text="Add New Person" 
        onclick="btnAddNew_Click" />
    <br />

<%--displays detail view of selected item in data grid--%>
<%--<h4><asp:Label ID="lblNew" runat="server" Text="Enter a new Person:"></asp:Label></h4>--%>
<br />
<asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="SqlDataSource3" DataKeyNames="PersonId" 
     AutoGenerateRows="False" OnItemUpdated="DetailsView1_ItemUpdated">
      
    <RowStyle Font-Bold="False" ForeColor="Black" />
    <FieldHeaderStyle Font-Bold="True" ForeColor="#2153AA" />
    <Fields>
        <%--Id--%>
        <asp:TemplateField HeaderText="Id">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("PersonId") %>'></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("PersonId") %>'></asp:TextBox>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label10" runat="server" Text='<%# Bind("PersonId") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <%--First Name--%>
        <asp:TemplateField HeaderText="First Name">
            <EditItemTemplate>
                <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvFirstName" ControlToValidate="txtFirstName" runat="server"
                    ErrorMessage="You must enter a First Name" ValidationGroup="mpplRequired"> </asp:RequiredFieldValidator> 
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvFirstName" ControlToValidate="txtFirstName" runat="server"
                    ErrorMessage="You must enter a First Name" ValidationGroup="mpplRequired"> </asp:RequiredFieldValidator> 
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <%--Last Name--%>
        <asp:TemplateField HeaderText="Last Name">
            <EditItemTemplate>
                <asp:TextBox ID="txtLastName" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvLastName" ControlToValidate="txtLastName" runat="server"
                    ErrorMessage="You must enter a Last Name" ValidationGroup="mpplRequired"> </asp:RequiredFieldValidator> 
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtLastName" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvLastName" ControlToValidate="txtLastName" runat="server"
                    ErrorMessage="You must enter a Last Name" ValidationGroup="mpplRequired"> </asp:RequiredFieldValidator> 
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <%--Address--%>
        <asp:TemplateField HeaderText="Address">
            <EditItemTemplate>
                <asp:TextBox ID="txtAddress" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvAddress" ControlToValidate="txtAddress" runat="server"
                    ErrorMessage="You must enter an Address" ValidationGroup="mpplRequired"> </asp:RequiredFieldValidator> 
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtAddress" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvAddress" ControlToValidate="txtAddress" runat="server"
                    ErrorMessage="You must enter an Address" ValidationGroup="mpplRequired"> </asp:RequiredFieldValidator> 
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label4" runat="server" Text='<%# Bind("Address") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <%--City--%>
        <asp:TemplateField HeaderText="City">
            <EditItemTemplate>
                <asp:TextBox ID="txtCity" runat="server" Text='<%# Bind("City") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvCity" ControlToValidate="txtCity" runat="server"
                    ErrorMessage="You must enter a City" ValidationGroup="mpplRequired"> </asp:RequiredFieldValidator> 
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtCity" runat="server" Text='<%# Bind("City") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvCity" ControlToValidate="txtCity" runat="server"
                    ErrorMessage="You must enter a City" ValidationGroup="mpplRequired"> </asp:RequiredFieldValidator> 
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label5" runat="server" Text='<%# Bind("City") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <%--State--%>
        <asp:TemplateField HeaderText="State">
            <EditItemTemplate>
                <asp:DropDownList ID="ddStates" runat="server" DataSourceID="sqlDataSource_states" Text='<%# Bind("State") %>' DataTextField="State" DataValueField="State"></asp:DropDownList>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:DropDownList ID="ddStates" runat="server" DataSourceID="sqlDataSource_states" Text='<%# Bind("State") %>' DataTextField="State" DataValueField="State"></asp:DropDownList>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("State") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <%--Zip--%>
        <asp:TemplateField HeaderText="Zip">
            <EditItemTemplate>
                <asp:TextBox ID="txtZip" runat="server" Text='<%# Bind("Zip") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvZip" ControlToValidate="txtZip" runat="server"
                    ErrorMessage="You must enter a Zip Code" ValidationGroup="mpplRequired"> </asp:RequiredFieldValidator> 
                <asp:RegularExpressionValidator ID="revZip" ControlToValidate="txtZip" runat="server"
                    ErrorMessage="You must enter a 5 digit zip" 
                    ValidationExpression="\d{5}(-\d{4})?" ValidationGroup="mpplRegExp"></asp:RegularExpressionValidator>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtZip" runat="server" Text='<%# Bind("Zip") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvZip" ControlToValidate="txtZip" runat="server"
                    ErrorMessage="You must enter a Zip Code" ValidationGroup="mpplRequired"> </asp:RequiredFieldValidator> 
                <asp:RegularExpressionValidator ID="revZip" ControlToValidate="txtZip" runat="server"
                    ErrorMessage="You must enter a 5 digit zip" 
                    ValidationExpression="\d{5}(-\d{4})?" ValidationGroup="mpplRegExp"></asp:RegularExpressionValidator>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label6" runat="server" Text='<%# Bind("Zip") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <%--Phone Number--%>
        <asp:TemplateField HeaderText="Phone Number">
            <EditItemTemplate>
                <asp:TextBox ID="txtPhone" runat="server" Text='<%# Bind("PhoneNumber") %>'></asp:TextBox>
                <asp:RegularExpressionValidator ID="revPhone" ControlToValidate="txtPhone" runat="server"
                    ErrorMessage="Please enter phone number with no symbols" 
                    ValidationExpression="\d{10}" ValidationGroup="mpplRegExp"></asp:RegularExpressionValidator>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtPhone" runat="server" Text='<%# Bind("PhoneNumber") %>'></asp:TextBox>
                <asp:RegularExpressionValidator ID="revPhone" ControlToValidate="txtPhone" runat="server"
                    ErrorMessage="Please enter a 10 digit phone number without symbols" 
                    ValidationExpression="\d{10}" ValidationGroup="mpplRegExp"></asp:RegularExpressionValidator>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label7" runat="server" Text='<%# Bind("PhoneNumber") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <%--Email--%>
        <asp:TemplateField HeaderText="Email">
            <EditItemTemplate>
                <asp:TextBox ID="txtEmail" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox>
                <asp:RegularExpressionValidator ID="revEmail" ControlToValidate="txtEmail" runat="server"
                    ErrorMessage="Please enter a valid email address" 
                    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ValidationGroup="mpplRegExp"></asp:RegularExpressionValidator>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="txtEmail" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox>
                <asp:RegularExpressionValidator ID="revEmail" ControlToValidate="txtEmail" runat="server"
                    ErrorMessage="Please enter a valid email address" 
                    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ValidationGroup="mpplRegExp"></asp:RegularExpressionValidator>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label8" runat="server" Text='<%# Bind("Email") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <%--Access Level--%>
        <asp:TemplateField HeaderText="Access Level">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Level") %>'></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Level") %>'></asp:TextBox>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label9" runat="server" Text='<%# Bind("Level") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <%--Wants Newsletter--%>
        <asp:TemplateField HeaderText="Wants Newsletter?">
            <EditItemTemplate>
                <asp:CheckBox ID="CheckBox1" runat="server" Text="Yes" 
                    Checked='<%# Bind("wantsNewsletter") %>' />
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:CheckBox ID="CheckBox1" runat="server" Text="Yes"
                    Checked='<%# Bind("wantsNewsletter") %>' />
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:CheckBox ID="CheckBox1" runat="server" Text="Yes"
                    Checked='<%# Bind("wantsNewsletter") %>' Enabled="false" />
            </ItemTemplate>
        </asp:TemplateField>
        <%--Footer Buttons--%>
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" ButtonType="Button" />
    </Fields>
    <HeaderStyle Font-Bold="True" ForeColor="#2153AA" />
    </asp:DetailsView>
    
    <div class="confirmLabel">
    <br />
            <asp:Label ID="lblConfirm" runat="server" Text="" Class="confirmLabel"></asp:Label>
    </div>

</div>